#!/bin/bash

#
# Flow stability for dynamic community detection https://arxiv.org/abs/2101.06131v2
#
# Copyright (C) 2021 Alexandre Bovet <alexandre.bovet@maths.ox.ac.uk>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


# This script runs the computation of the Laplacian and transition matrices 
# for the case of the APS dataset



TIMESTAMP=$(date +%s)

JNAME="${TIMESTAMP}"

NCPU=8

# numpy/scipy number of cores
export OPENBLAS_NUM_THREADS=1
export OMP_NUM_THREADS=1

# to use int64 for MKL indexing. To allow more than 2**31 -1 elements
export MKL_INTERFACE_LAYER=ILP64


NETFILENAME="aps_monthly_lcc_net.pickle"

RUNDIR="$HOME/rundir"

DATADIRBASE="$HOME/datadir"

mkdir -p $DATADIRBASE


LAPINTERTRANSDIR="$DATADIRBASE/lapl_intertransmat"

mkdir -p $LAPINTERTRANSDIR


NETNAME="aps_monthly"

# final grid resolution in unit of slices
INT_LENGTH=10 # 10 years

TAU_WS=(3650)


# compute laplacians and intertransition matrices
python3 -u $RUNDIR/run_laplacians_transmat.py \
        --datadir $DATADIRBASE \
        --savedir $LAPINTERTRANSDIR \
        --net_filename $NETFILENAME \
        --net_name $NETNAME \
        --save_slice_trans \
        --ncpu $NCPU \
        --tau_w_list ${TAU_WS[*]} \
        --save_inter_T \
        --time_slices_from_net_file \
        --not_lin_transmat \
        --compress_slice_trans \
        --compress_inter_T \
        --force_csr \
        --tol 1e-6 \
        > output_${JNAME}_lptm.txt 2> error_${JNAME}_lptm.txt
# end
